package cn.niit.pm.service.impl;

import cn.niit.pm.dao.LeaveFormMapper;
import cn.niit.pm.entity.Attendance;
import cn.niit.pm.entity.LeaveForm;
import cn.niit.pm.entity.Train;
import cn.niit.pm.service.LeaveFormService;
import cn.niit.pm.service.ServiceInterface;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 请假管理
 * @author Yupengfei
 */
@Component
@Service
public class LeaveFormServiceImpl implements ServiceInterface<LeaveForm> {
    @Resource
    private LeaveFormMapper mapper;


    @Override
    public PageInfo select(LeaveForm leaveForm, int pageSize, int pageNumber) {
        //使用PageHelper设置分页，为了安全分页，后边最好紧跟mybatis mapper方法
        //注意这里看起来似乎是属于内存分页，但其实PageHelper插件对mybatis执行流程进行了增强，属于物理分页
        PageHelper.startPage(pageSize, pageNumber);
        List<LeaveForm> page =  mapper.findByPage(leaveForm);
        PageInfo<LeaveForm> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }

    @Override
    public void insert(LeaveForm leaveForm) {
        mapper.insert(leaveForm);
    }

    @Override
    public void update(LeaveForm leaveForm) {
        mapper.update(leaveForm);
    }

    @Override
    public void delete(Integer id) {
        mapper.deleteById(id);
    }

    @Override
    public LeaveForm selectById(Long id) {
        return mapper.selectById(id);
    }

    public List<Train> selectTrainerById() {
        return mapper.selectTrainerById();
    }
}
